package com.sgb.kjwl.view.ui.adapter.self.packers;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import androidx.databinding.library.baseAdapters.BR;

import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.LayoutRecyclerFlowLayoutBinding;
import com.sgb.kjwl.model.entity.self.SelfTeamIntroduceEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class FlowLayoutAdapter2 extends BaseRecycleAdapter<SelfTeamIntroduceEntity.ServiceAreasBean> {

    private boolean isDelete;
    private DeleteImpl mDeleteImpl;

    public void setDeleteImpl(DeleteImpl mDeleteImpl) {
        this.mDeleteImpl = mDeleteImpl;
    }

    public FlowLayoutAdapter2(Context context, List<SelfTeamIntroduceEntity.ServiceAreasBean> datas) {
        super(context, R.layout.layout_recycler_flow_layout, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final SelfTeamIntroduceEntity.ServiceAreasBean entity) {
        holder.setBinding(BR.viewModel, null);
        showWorkType(((LayoutRecyclerFlowLayoutBinding) holder.getmBinding()).tvType, entity);
        ((LayoutRecyclerFlowLayoutBinding) holder.getmBinding()).rlDelete.setVisibility(isDelete ? View.VISIBLE : View.GONE);
        ((LayoutRecyclerFlowLayoutBinding) holder.getmBinding()).rlDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isDelete()) {
                    getDatas().remove(holder.getAdapterPosition());
                    mDeleteImpl.delete();
                    notifyDataSetChanged();
                }
            }
        });
    }

    private void showWorkType(TextView tvType, SelfTeamIntroduceEntity.ServiceAreasBean entity) {
        tvType.setText(entity.getName());
    }

    public boolean isDelete() {
        return isDelete;
    }

    public void setDelete(boolean delete) {
        isDelete = delete;
        notifyDataSetChanged();
    }

    public interface DeleteImpl{
        void delete();
    }
}
